// Created by carolsail
import ViewBase from './../xf/ViewBase';
import LData from '../manager/LData';
import PrefabManager from '../xf/manager/PrefabManager';
import SoundManager from '../manager/SoundManager';
import SoundPath from '../struct/SoundPath';

const { ccclass, property } = cc._decorator;

@ccclass
export default class MdSet extends ViewBase {


    private static _inst:MdSet;

    public static get inst()
    {
        if(this._inst==null  || this._inst.node==null)
        {
            let v=cc.instantiate(PrefabManager.getPrefab("SetView"));

            this._inst=v.getComponent(MdSet);
        }

        return this._inst;
    }


    @property(cc.Sprite)
    btnMusic: cc.Sprite = null

    @property(cc.Sprite)
    btnSound: cc.Sprite = null

    @property(cc.Node)
    btnClose: cc.Node = null

    @property(cc.SpriteFrame)
    kai: cc.SpriteFrame = null

    @property(cc.SpriteFrame)
    guan: cc.SpriteFrame = null


    start() {
        this.resetMusic();
        this.resetSound();
    }



    onClose() {
        this.hideView();
    }

    onSound()
     {
        LData.yx =  !LData.yx

        cc.sys.localStorage.setItem("sound",LData.yx);

        this.resetSound()
    }

    onMusic() {
        LData.yy =  !LData.yy
        console.log("LData.yy==>"+LData.yy)
        cc.sys.localStorage.setItem("playMusic",LData.yy);

        if ( LData.yy==true)
         {
            SoundManager.playBgm();
        }
         else 
         {
            SoundManager.stopBgm();
        }
        

        this.resetMusic()
    }

    resetMusic() {
        console.log(typeof LData.yy)
        this.btnMusic.spriteFrame = LData.yy==true?this.kai:this.guan
     
    }

    resetSound() {
        console.log("resetSound==>"+(LData.yx==true))

        this.btnSound.spriteFrame = LData.yx==true?this.kai:this.guan
    }

}
